package com.huangliusong.demo3;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * bean作用范围的测试
 */
public class SpringDemo3 {

    public void test(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
        Person person1=(Person)applicationContext.getBean("person");
        Person person2=(Person)applicationContext.getBean("person");
        System.out.println(person1==person2);
        System.out.println(person2);
    }



    public void test1(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
        Man person1=(Man)applicationContext.getBean("man");
        Man person2=(Man)applicationContext.getBean("man");
        person1.run();
        ((ClassPathXmlApplicationContext) applicationContext).close();
    }


    @Test
    public void test3(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
        UserDao userDao=(UserDao)applicationContext.getBean("userDao");
       userDao.save();
    }
}
